package top.kaoshanji.p3ch26a;

import java.io.File;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * author kaoshanji
 * ^_^
 * create time 2025/3/4 10:57
 */
public class BasicLambda {

    File file = new File(".");

    // 代码清单-p3ch26a-630页a：Lambda语法fileV1
    public void fileV1() {

        File[] files = file.listFiles((File dir, String name) -> {
            if (name.endsWith(".txt")) {
                return true;
            }

            return false;
        });

    }

    // 代码清单-p3ch26a-630页b：Lambda语法fileV2
    public void fileV2() {

        File[] files = file.listFiles((File dir, String name) -> {
           return name.endsWith(".txt");
        });

    }

    // 代码清单-p3ch26a-630页c：Lambda语法fileV3
    public void fileV3() {
        File[] files = file.listFiles((File dir, String name) -> name.endsWith(".txt"));
    }

    // 代码清单-p3ch26a-630页d：Lambda语法fileV4
    public void fileV4() {
        File[] files = file.listFiles(((dir, name) -> name.endsWith(".txt")));
    }

    // 代码清单-p3ch26a-630页e：排序的代码用Lambda表达式
    public void sortV1() {
        File[] files = file.listFiles((dir, name) -> name.endsWith(".txt"));
        Arrays.sort(files, (f1, f2) -> f1.getName().compareTo(f2.getName()));
    }

    // 代码清单-p3ch26a-631页a：提交任务的代码用Lambda表达式
    public void submitV1() {
        ExecutorService executor = Executors.newFixedThreadPool(100);
        executor.submit(() -> System.out.println("hello"));
    }


}
